//
//  UIBarButtonItem+Category.swift
//  PopViewMenu
//  UIBarButtonItem 延展
//  Created by Rookie_YX on 16/5/27.
//  Copyright © 2016年 YX_Rookic. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    // 如果在func前面加class, 就相当于oc中的 "+"
    /**
     自定义导航栏按钮
     
     - parameter imageName: 按钮图片名称
     - parameter target:    哪个按钮传递事件
     - parameter action:    哪个按钮传递事件函数
     
     - returns:UIBarButtonItem
     */
    class func creaBarButtonItem(imageName:String, target:AnyObject?, action:Selector)->UIBarButtonItem{
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        btn.addTarget(target, action:action, forControlEvents: UIControlEvents.TouchUpInside)
        btn.sizeToFit()
        return UIBarButtonItem(customView: btn)
    }
}